<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
$condition = array();

($zone = strval($_GET['zone'])) || ($zone = 'city');
if ( $zone ) { $condition['zone'] = $zone; }

$cates = get_zones();

/* 筛选一二级分类 */
$type = strval($_GET['type']);
if('one' == $type){
    $condition['fid'] = 0;
}elseif('two' == $type){
    $condition[] = 'fid != 0';
}
/* 筛选一二级分类 end */

$count = Table::Count('category', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);

$categories = DB::LimitQuery('category', array(
	'condition' => $condition,
	'order' => 'ORDER BY display ASC, sort_order DESC, id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));
$groups = Table::Fetch('category', Utility::GetColumn($categories, 'fid'));
if('area' == $_GET['zone']){
    $areas = DB::LimitQuery('area', array(
		'order' => 'ORDER BY sort_order DESC',
		));
	$city_ids = Utility::GetColumn($areas, 'city_id');
	$citys = Table::Fetch('category', $city_ids);
    include template('manage_category_area'); 
}else{
    include template('manage_category_index');   
}